import { observable, action } from 'mobx';
import { toJS } from 'mobx';

export default class MainStore {
  @observable visible = false;
  @observable pathMap = [
    { key: 'communication', name: '协作交流', path: '/communication' },
    { key: 'approval', name: '协作审批', path: '/approval' },
    { key: 'apply', name: '协作申请', path: '/apply' },
    { key: 'center', name: '个人中心', path: '/center' },
    { key: 'detail', name: '详情页面', path: '/detail' },
    { key: 'hrmjion', name: '其他参与人参与的协作', path: '/hrmjion' }
  ];

  @action getPath = key => toJS(this.pathMap).filter(v => v.key === key)[0].path

  @action getKey = path => path !== '/' && toJS(this.pathMap).filter(v => path.indexOf(v.path) > -1)[0].key

  @action setStoreState = (params) => {
    Object.keys(params).forEach(key => {
      this[key] = params[key];
    })
  }
}